#include <iostream>
#include <queue>
using namespace std;
using ll=long long;
int main() {

	priority_queue<ll,vector<ll>,greater<ll>> q;
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		int t;
		cin>>t;
		q.push(t);
	}
	ll nRet=0;
	while(q.size()>=2){
		int t1=q.top();
		q.pop();
		int t2=q.top();
		q.pop();
		nRet+=t1+t2;
		q.push(t1+t2);
	}
	cout<<nRet<<endl;
	
	return 0;
}
